<div id="paperTitle" style="font-weight: bold;text-align: center;font-size: 24px;">
</div>
<div id="paperRemark" style="text-align: center;font-size: 14px;">
</div>
<div id="paperGroup" style="text-align: center;font-size: 14px;">
</div>
<div  id="paperView">
</div>
<script>
    layui.use(['index', 'form', 'table', 'util', 'config', 'admin', 'layer'], function () {
        var admin=layui.admin;
        var tempData = admin.getTempData("paper_data");
        let epname = tempData.epname;
        let gpname=tempData.gpname;
        let remark=tempData.remark;
        $("#paperTitle").html(epname);
        $("#paperRemark").html(remark);
        $("#paperGroup").html("参考小组："+gpname);

        admin.req("api-exam/examPaper/findPaperQue",{expaid:tempData.expaid},function (res) {
            let data=res.data;
            generatorHtml(data);
        },"get");
        //生成html
        function generatorHtml(data){
            for (let i = 0; i <data.length; i++) {

            }
            let html1 = choice(data);
            let html2 = notChoice(data);
            $("#paperView").html(html1+html2);
        }
        //选择题
        function choice(data) {
            let f=true;
            let html='<div style="font-weight: bold">一、选择题</div>\n';
            let num=1;
            for (let i = 0; i < data.length; i++) {
                if(data[i].tpname=='选择题'){
                    html += '<div class="layui-form-item">\n' +
                        '    <label class="layui-form-label">'+num+'、('+data[i].score+'分)</label>\n' +
                        '    <div class="layui-input-block" contenteditable="true">\n' +
                        '        <textarea  class="layui-textarea"  autoHeight="true" readonly>'+data[i].qtitle+'</textarea>\n' +
                        '    </div>\n' +
                        '</div>\n' +
                        '<div class="layui-form-item">\n' +
                        '    <label class="layui-form-label">A、</label>\n' +
                        '    <div class="layui-input-inline">\n' +
                        '        <input class="layui-input" value="'+data[i].optioA+'" readonly >\n' +
                        '    </div>\n' +
                        '    <label class="layui-form-label">B、</label>\n' +
                        '    <div class="layui-input-inline">\n' +
                        '        <input  class="layui-input" value="'+data[i].optioB+'" readonly >\n' +
                        '    </div>\n' +
                        '    <label class="layui-form-label">C、</label>\n' +
                        '    <div class="layui-input-inline">\n' +
                        '        <input class="layui-input" value="'+data[i].optioC+'" readonly >\n' +
                        '    </div>\n' +
                        '    <label class="layui-form-label">D、</label>\n' +
                        '    <div class="layui-input-inline">\n' +
                        '        <input  class="layui-input" value="'+data[i].optioD+'" readonly >\n' +
                        '    </div>\n' +
                        '</div>\n' +
                        '<div class="layui-form-item layui-bg-gray">\n' +
                        '    <label class="layui-form-label">答案</label>\n' +
                        '    <div class="layui-input-block">\n' +
                        '        <input class="layui-input layui-bg-gray" value="'+data[i].answer+'" readonly >\n' +
                        '    </div>\n' +
                        '</div>';
                    num++;
                    f=false;
                }
            }
            if(f){
                html='';
            }
            return html;
        }
        //非选择题html
        function notChoice(data) {
            let flag=true;
            let html='<div style="font-weight: bold">二、问答题</div>\n';
            let num=1;
            for (let i = 0; i < data.length; i++) {
                if(data[i].tpname!="选择题"){
                    html += '<div class="layui-form-item">\n' +
                        '    <label class="layui-form-label">'+num+'、('+data[i].score+'分) </label>\n' +
                        '    <div class="layui-input-block" contenteditable="true">\n' +
                        '        <textarea  class="layui-textarea"  autoHeight="true" readonly>'+data[i].qtitle+'</textarea>\n' +
                        '    </div>\n' +
                        '</div>\n' +
                        '<div class="layui-form-item layui-bg-gray">\n' +
                        '    <label class="layui-form-label">答案</label>\n' +
                        '    <div class="layui-input-block">\n' +
                        '        <textarea  class="layui-textarea layui-bg-gray"  autoHeight="true" readonly>'+data[i].answer+'</textarea>\n' +
                        '    </div>\n' +
                        '</div>';
                    num++;
                    flag=false;
                }
            }
            if(flag){
                html='';
            }
            return html;
        }
    });


    /**
     * textarea高度自适应
     */
    $(function(){
        $.fn.autoHeight = function(){
            function autoHeight(elem){
                elem.style.height = 'auto';
                elem.scrollTop = 0; //防抖动
                elem.style.height = elem.scrollHeight +5+ 'px';
            }
            this.each(function(){
                autoHeight(this);
                $(this).on('keyup', function(){
                    autoHeight(this);
                });
            });
        }
        $('textarea[autoHeight]').autoHeight();
    })
</script>